// 模拟 API 响应
export const parseUIInstruction = async (instruction) => {
  // 模拟网络延迟
  await new Promise(resolve => setTimeout(resolve, 800))
  
  if (instruction.includes('Dashboard') || instruction.includes('面板')) {
    return {
      component_config: {
        component_type: "dashboard",
        title: "销售数据统计面板",
        layout: "grid",
        grid_config: { rows: 2, cols: 2 },
        widgets: [
          {
            type: "line_chart",
            title: "月度销售额",
            data_source: "mock_sales_data",
            x_field: "month",
            y_field: "amount",
            style: { height: "300px" }
          },
          {
            type: "pie_chart",
            title: "产品销量占比",
            data_source: "mock_product_data",
            name_field: "product",
            value_field: "sales",
            style: { height: "300px" }
          },
          {
            type: "statistic_card",
            title: "总销售额",
            value: "¥ 156,800",
            trend: "up",
            style: { height: "150px" }
          },
          {
            type: "statistic_card",
            title: "同比增长",
            value: "+12.5%",
            trend: "up",
            style: { height: "150px" }
          }
        ]
      }
    }
  } else if (instruction.includes('表单') || instruction.includes('form')) {
    return {
      component_config: {
        component_type: "form",
        title: "用户信息注册表单",
        fields: [
          {
            label: "用户名",
            type: "input",
            name: "username",
            rules: ["required", "minLength:3"],
            placeholder: "请输入用户名"
          },
          {
            label: "手机号",
            type: "input",
            name: "phone",
            rules: ["required", "phone"],
            placeholder: "请输入手机号"
          },
          {
            label: "邮箱",
            type: "input",
            name: "email",
            rules: ["required", "email"],
            placeholder: "请输入邮箱"
          },
          {
            label: "所属部门",
            type: "select",
            name: "department",
            options: [
              { label: "研发部", value: "rd" },
              { label: "产品部", value: "product" },
              { label: "市场部", value: "marketing" },
              { label: "运营部", value: "operations" }
            ]
          },
          {
            label: "入职日期",
            type: "date",
            name: "hire_date",
            rules: ["required"]
          }
        ],
        submit_text: "提交注册",
        reset_text: "重置表单"
      }
    }
  }
  
  throw new Error('无法识别的指令类型')
}